# 实现WSGI协议中的application接口方法
import re


def application(envrion,start_response):
    """
    envrion-->字典，保存访问路径
    start_response -->用来回调，实现将web应用的处理结构回传给调用者
    返回值-->响应体，根据访问路径得到相应的值
    """
    url_path = envrion['PATH_INFO']
    if url_path == '/index.py':
        path = './templates/index.html'
        with open(path,'r') as f:
            file_content = f.read()
        row_str = """
                    <tr>
                        <td>1</td>
                        <td>000007</td>
                        <td>全新好</td>
                        <td>10.01%</td>
                        <td>4.40%</td>
                        <td>16.05</td>
                        <td>14.60</td>
                        <td>2017-07-18</td>
                        <td>
                            <input type="button" value="添加" id="toAdd" name="toAdd" systemidvaule="000007">
                        </td>
                    </tr>  """
        all_data=''
        for i in range(20):
            all_data+=row_str
        file_content = re.sub(r'\{%content%\}',all_data,file_content)

    elif url_path == '/center.py':
        file_content = 'center page ...'
    else:
        file_content = 'other page ...'
    # 回调start_response函数，将响应状态信息回传给服务器
    start_response('200 OK',[('Content-Type','text/html;charset=utf-8')])
    #返回响应的数据内容
    return file_content




